package com.cmower.baeldung.arrays1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

public class ArraysDemo {
    public static void main(String[] args) {
        String[] intro = new String[]{"沉", "默", "王", "二"};

int[] arr = new int[]{1, 2, 3, 4};
Arrays.parallelPrefix(arr, (left, right) -> {
    System.out.println(left + "，" + right);
    return left + right;
});
System.out.println(Arrays.toString(arr));

        int[] array = new int[10];
        Arrays.setAll(array, i -> i * 10);
// 输出 [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
        System.out.println(Arrays.toString(array));


        List<String> rets = Arrays.asList(intro);
        System.out.println(rets.contains("二"));

        List<String> rets1 = new ArrayList<>(Arrays.asList(intro));
        rets1.add("三");
        rets1.remove("二");


        System.out.println(Arrays.stream(intro).count());
//System.out.println(Arrays.stream(intro, 1, 2).count());

        String[] intro1 = new String[]{"chen", "mo", "wang", "er"};
        String[] sorted = Arrays.copyOf(intro1, 4);
        Arrays.sort(sorted);
        System.out.println(Arrays.toString(sorted));

        int exact = Arrays.binarySearch(sorted, "wang");
        System.out.println(exact);
        int caseInsensitive = Arrays.binarySearch(sorted, "Wang", String::compareToIgnoreCase);
        System.out.println(caseInsensitive);

        System.out.println(Arrays.hashCode(intro));
        System.out.println(Arrays.hashCode(new String[]{"沉", "默", "王", "二"}));


        boolean result = Arrays.equals(new String[]{"沉", "默", "王", "二"}, intro);
        System.out.println(result);
        boolean result1 = Arrays.equals(new String[]{"沉", "默", "王", "三"}, intro);
        System.out.println(result1);


        String[] revised = Arrays.copyOf(intro, 3);
        String[] expanded = Arrays.copyOf(intro, 5);
        System.out.println(Arrays.toString(revised));
        System.out.println(Arrays.toString(expanded));

        String[] abridgement = Arrays.copyOfRange(intro, 0, 3);
        System.out.println(Arrays.toString(abridgement));

        String[] abridgementExpanded = Arrays.copyOfRange(intro, 0, 6);
        System.out.println(Arrays.toString(abridgementExpanded));


        String[] stutter = new String[4];
        Arrays.fill(stutter, "沉默王二");
        System.out.println(Arrays.toString(stutter));


    }
}
